package com.gitee.vueantd.upload.service.dto;

import com.gitee.vueantd.common.utils.ElAdminConstant;
import com.gitee.vueantd.common.utils.PubUtil;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.codec.digest.DigestUtils;

import javax.servlet.http.HttpServletRequest;

@Getter
@Setter
@NoArgsConstructor
@ToString
public class ChunkRequest {
  public Long chunkIndex;
  public Long chunkSize;
  public Long fileSize;
  public String fileName;
  public Integer fileType;
  public Long nodeId;
  public String chunkHash;
  public Long modifyTime;
  public Long totalChunks;
  public String userName;
  public String fileHash;

  public ChunkRequest(HttpServletRequest request) {
    chunkIndex = PubUtil.getLong(request.getParameter("resumableChunkNumber"), -1L);
    chunkSize = PubUtil.getLong(request.getParameter("resumableChunkSize"), -1L);
    fileSize = PubUtil.getLong(request.getParameter("resumableTotalSize"), -1L);
    fileName = request.getParameter("resumableFilename");
    fileHash = DigestUtils.md5Hex(request.getParameter("resumableFileHash") + ElAdminConstant.UPLOAD_FILE_HASH_SALT);
    fileType = PubUtil.getInteger(request.getParameter("resumableFileType"), -1);
    nodeId = PubUtil.getLong(request.getParameter("resumableNodeId"), -1L);
    chunkHash = request.getParameter("resumableChunkHash");
    modifyTime = PubUtil.getLong(request.getParameter("resumableModifyTime"), -1L);
    totalChunks = PubUtil.getLong(request.getParameter("resumableTotalChunks"), -1L);
    userName = request.getParameter("resumableUserName");
  }
}
